﻿using Client;
using Shared.DJDBDK;
using Shared.Method;
using Shared.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ModemWrite
{
    public partial class FormModemSystem : Form
    {      

        private string _softType = "0";//0，信息写入；1，出厂检查，2，信息检查，3，语音测试

        private string _stationIp = "127.0.0.1";//过站软件IP地址

        //private string _ifReset = "0";//0，不还原出厂设置，1，还原出厂设置

        //private string _ifWait = "0";//0，不等到；1，等待；

        private string _defaultSn = "000000000000";

        /// <summary>
        /// 光猫IP地址
        /// </summary>
        private string _modemAddress = "192.168.1.1";
        private string _modemUser = "admin";
        private string _modemPwd = "1234";


        //使用键值对存储IP/PORT/FORM
        private Dictionary<int, WriteGroup> _dictWrite = null;

        private Dictionary<int, WriteGroupScan> _dictWriteScan = null;

        //使用键值对存储IP/PORT/FORM RESET
        private Dictionary<int, ResetGroup> _dictReset = null;

        //信息检查
        private Dictionary<int, MsgCheckGroup> _dictCheck = null;

        //语音测试激活
        private Dictionary<int, VoiceTestGroup> _dictVoice = null;

        private Dictionary<int, TestTwoGroup> _dictTestTwo = null;
        //缓存DeviceType
        private List<Device_Type> _listType = null;

        //保存窗口状态的数组
        private List<int> _formFree = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8 };
        private readonly object _lockObj = new object();

        //清空arp缓存
        //private Task _clearArp = null;
        //private string _portOne = null, _portTwo = null;


        public FormModemSystem()
        {
            InitializeComponent();
        }

        private void FormModemWrite_Load(object sender, EventArgs e)
        {
            //清空缓存线程
            //ClearArp();
            //MethodWcf.KEY = "RssPmq&AwYcc7<98Bux";

            //软件版本
            string version = Application.ProductVersion.ToString();

            //获取软件类型
            string type = AppSetting.GetValue("SoftType");
            if (string.IsNullOrEmpty(type) == false) _softType = type;


            //从APPCONFIG获取配置
            string stationIp = AppSetting.GetValue("StationSoftIP");
            if (string.IsNullOrEmpty(stationIp) == false)  _stationIp= stationIp;

            //光猫IP
            string modemIp = AppSetting.GetValue("IpAddress");
            if (string.IsNullOrEmpty(modemIp) == false) _modemAddress = modemIp;

            //光猫用户
            string modemUser = AppSetting.GetValue("UserName");
            if (string.IsNullOrEmpty(modemUser) == false) _modemUser = modemUser;

            //光猫密码
            string modemPwd = AppSetting.GetValue("Password");
            if (string.IsNullOrEmpty(modemPwd) == false) _modemPwd = modemPwd;


            //获取devicetype的list
            Device_Type typeW = new Device_Type();
            var selectType = MethodWcf.SelectDeviceTypeClient(typeW);
            if (selectType.result == false)
            {
                MessageBox.Show("获取产品类型数据失败，不能进行信息写入的工作！");
                Close();//关闭窗体
                return;
            }

            _listType = selectType.value;//给type赋值

            //type = "0";

            //使用键值对初始化
            if (type == "0")
            {
                //修改软件名称
                this.Text = string.Format("友创达信息写入软件 V{0}", version);

                //this.Text = string.Format("友创达信息写入软件_跳转BOB返工定制版 V{0}", version);//定制版本

                //默认GPON的SN号码
                string defaultSn = AppSetting.GetValue("DefaultSn");
                if (string.IsNullOrEmpty(defaultSn) == false) _defaultSn = defaultSn;

                ////获取需要测试的端口的速度
                //string portOne = AppSetting.GetValue("PortOne");
                //if (string.IsNullOrEmpty(portOne) == false) _portOne = portOne;

                ////端口号二
                //string portTwo = AppSetting.GetValue("PortTwo");
                //if (string.IsNullOrEmpty(portTwo) == false) _portTwo = portTwo;

                //是否写BOB信息
                string writeBob = AppSetting.GetValue("WriteBob");

                _dictWrite = new Dictionary<int, WriteGroup>();
                for (int i = 1; i <= 8; i++)
                {
                    WriteGroup group = new WriteGroup();

                    string localIp = AppSetting.GetValue("LocalIp" + i);
                    if (string.IsNullOrEmpty(localIp) == false) group.LocalIp = localIp;
                    string localPort = AppSetting.GetValue("LocalPort" + i);
                    int port;
                    if (string.IsNullOrEmpty(localPort) == false && int.TryParse(localPort, out port)) group.LocalPort = port;

                    FlowLayoutPanel panel = null;

                    //获取需要调用的panel
                    switch (i)
                    {
                        case 1:
                            panel = this.flowLayoutPanel1;
                            break;
                        case 2:
                            panel = this.flowLayoutPanel2;
                            break;
                        case 3:
                            panel = this.flowLayoutPanel3;
                            break;
                        case 4:
                            panel = this.flowLayoutPanel4;
                            break;
                        case 5:
                            panel = this.flowLayoutPanel5;
                            break;
                        case 6:
                            panel = this.flowLayoutPanel6;
                            break;
                        case 7:
                            panel = this.flowLayoutPanel7;
                            break;
                        case 8:
                            panel = this.flowLayoutPanel8;
                            break;
                        default:
                            break;
                    }

                    //初始化产品
                    panel.Controls.Clear();
                    group.RealWrite = new FormRealWrite(group.LocalIp, group.LocalPort, _modemAddress, _modemUser, _modemPwd, i, _listType, _defaultSn, _stationIp, writeBob);
                    group.RealWrite.OnWrite += new Action<int>(OnWrite_Action);
                    group.RealWrite.OnEndAndWrite += new Action<string, int>(OnEndAndWrite);
                    group.RealWrite.Show();
                    panel.Controls.Add(group.RealWrite);

                    _dictWrite.Add(i, group);
                }
            }

            else if (type == "1")
            {
                //修改软件名称
                this.Text = string.Format("友创达出厂检查软件 V{0}", version);

                //重置光猫
                _dictReset = new Dictionary<int, ResetGroup>();

                for (int i = 1; i <= 8; i++)
                {
                    //获取是否还原的配置
                    //string ifWait = AppSetting.GetSetValue("IfWait");
                    //if (string.IsNullOrEmpty(ifWait) == false) _ifWait = ifWait;

                    ResetGroup group = new ResetGroup();

                    string localIp = AppSetting.GetValue("LocalIp" + i);
                    if (string.IsNullOrEmpty(localIp) == false) group.LocalIp = localIp;
                    string localPort = AppSetting.GetValue("LocalPort" + i);
                    int port;
                    if (string.IsNullOrEmpty(localPort) == false && int.TryParse(localPort, out port)) group.LocalPort = port;

                    FlowLayoutPanel panel = null;
                    //获取需要调用的panel
                    switch (i)
                    {
                        case 1:
                            panel = this.flowLayoutPanel1;
                            break;
                        case 2:
                            panel = this.flowLayoutPanel2;
                            break;
                        case 3:
                            panel = this.flowLayoutPanel3;
                            break;
                        case 4:
                            panel = this.flowLayoutPanel4;
                            break;
                        case 5:
                            panel = this.flowLayoutPanel5;
                            break;
                        case 6:
                            panel = this.flowLayoutPanel6;
                            break;
                        case 7:
                            panel = this.flowLayoutPanel7;
                            break;
                        case 8:
                            panel = this.flowLayoutPanel8;
                            break;
                        default:
                            break;
                    }

                    //初始化产品
                    panel.Controls.Clear();
                    group.resetModem = new FormFactoryCheck(group.LocalIp, group.LocalPort, _modemAddress, _modemUser, _modemPwd, i, _listType, _stationIp);
                    group.resetModem.OnWrite += new Action<int>(OnFactory_Action);
                    group.resetModem.Show();
                    panel.Controls.Add(group.resetModem);

                    _dictReset.Add(i, group);
                }
            }

            else if (type == "2")
            {
                ////获取是否还原的配置
                //string ifReset = AppSetting.GetSetValue("IfReset");
                //if (string.IsNullOrEmpty(ifReset) == false) _ifReset = ifReset;

                //修改软件名称
                this.Text = string.Format("友创达信息检查软件 V{0}", version);

                //信息检查
                _dictCheck = new Dictionary<int, MsgCheckGroup>();
                for (int i = 1; i <= 8; i++)
                {
                    MsgCheckGroup group = new MsgCheckGroup();

                    string localIp = AppSetting.GetValue("LocalIp" + i);
                    if (string.IsNullOrEmpty(localIp) == false) group.LocalIp = localIp;
                    string localPort = AppSetting.GetValue("LocalPort" + i);
                    int port;
                    if (string.IsNullOrEmpty(localPort) == false && int.TryParse(localPort, out port)) group.LocalPort = port;

                    FlowLayoutPanel panel = null;

                    //获取需要调用的panel
                    switch (i)
                    {
                        case 1:
                            panel = this.flowLayoutPanel1;
                            break;
                        case 2:
                            panel = this.flowLayoutPanel2;
                            break;
                        case 3:
                            panel = this.flowLayoutPanel3;
                            break;
                        case 4:
                            panel = this.flowLayoutPanel4;
                            break;
                        case 5:
                            panel = this.flowLayoutPanel5;
                            break;
                        case 6:
                            panel = this.flowLayoutPanel6;
                            break;
                        case 7:
                            panel = this.flowLayoutPanel7;
                            break;
                        case 8:
                            panel = this.flowLayoutPanel8;
                            break;
                        default:
                            break;
                    }

                    //初始化产品
                    panel.Controls.Clear();
                    group.msgCheck = new FormMsgCheck(group.LocalIp, group.LocalPort, _modemAddress, _modemUser, _modemPwd, i, _listType, _stationIp);
                    group.msgCheck.OnWrite += new Action<int>(OnCheck_Action);
                    group.msgCheck.Show();
                    panel.Controls.Add(group.msgCheck);

                    _dictCheck.Add(i, group);
                }
            }

            else if (type == "3")
            {
                //语音测试
                //修改软件名称
                this.Text = string.Format("友创达语音测试软件 V{0}", version);

                //初始化语音卡
                string msg;
                bool initVoice = VoiceBaseClass.InitVoiceCard(out msg);

                if (initVoice == false)
                {
                    MessageBox.Show("初始化语音卡失败");
                    //Close();
                }

                if (VoiceBaseClass.TotalLine != 8) { MessageBox.Show("初始化语音接口数目不为8，请检查"); }

                //语音测试类集合
                _dictVoice = new Dictionary<int, VoiceTestGroup>();

                for (int i = 1; i <= 8; i++)
                {
                    VoiceTestGroup group = new VoiceTestGroup();

                    string localIp = AppSetting.GetValue("LocalIp" + i);
                    if (string.IsNullOrEmpty(localIp) == false) group.LocalIp = localIp;
                    string localPort = AppSetting.GetValue("LocalPort" + i);
                    int port;
                    if (string.IsNullOrEmpty(localPort) == false && int.TryParse(localPort, out port)) group.LocalPort = port;

                    FlowLayoutPanel panel = null;
                    //获取需要调用的panel
                    switch (i)
                    {
                        case 1:
                            panel = this.flowLayoutPanel1;
                            break;
                        case 2:
                            panel = this.flowLayoutPanel2;
                            break;
                        case 3:
                            panel = this.flowLayoutPanel3;
                            break;
                        case 4:
                            panel = this.flowLayoutPanel4;
                            break;
                        case 5:
                            panel = this.flowLayoutPanel5;
                            break;
                        case 6:
                            panel = this.flowLayoutPanel6;
                            break;
                        case 7:
                            panel = this.flowLayoutPanel7;
                            break;
                        case 8:
                            panel = this.flowLayoutPanel8;
                            break;
                        default:
                            break;
                    }

                    //初始化产品
                    panel.Controls.Clear();
                    group.voiceTest = new FormRealTest(group.LocalIp, group.LocalPort, _modemAddress, _modemUser, _modemPwd, i, _stationIp, i - 1, _listType);
                    //group.voiceTest.OnVoiceResult += VoiceTest_OnVoiceResult;
                    group.voiceTest.Show();

                    panel.Controls.Add(group.voiceTest);
                }
            }

            else if (type == "4")
            {
                //融合测试
                //修改软件名称
                this.Text = string.Format("友创达语音信息检查软件 V{0}", version);


                //初始化语音卡
                string msg;
                bool initVoice = VoiceBaseClass.InitVoiceCard(out msg);

                if (initVoice == false)
                {
                    MessageBox.Show("初始化语音卡失败");
                    //Close();
                }

                if (VoiceBaseClass.TotalLine != 8) { MessageBox.Show("初始化语音接口数目不为8，请检查"); }

                //语音测试类集合
                _dictTestTwo = new Dictionary<int, TestTwoGroup>();

                for (int i = 1; i <= 8; i++)
                {
                    TestTwoGroup group = new TestTwoGroup();

                    string localIp = AppSetting.GetValue("LocalIp" + i);
                    if (string.IsNullOrEmpty(localIp) == false) group.LocalIp = localIp;
                    string localPort = AppSetting.GetValue("LocalPort" + i);
                    int port;
                    if (string.IsNullOrEmpty(localPort) == false && int.TryParse(localPort, out port)) group.LocalPort = port;

                    FlowLayoutPanel panel = null;
                    //获取需要调用的panel
                    switch (i)
                    {
                        case 1:
                            panel = this.flowLayoutPanel1;
                            break;
                        case 2:
                            panel = this.flowLayoutPanel2;
                            break;
                        case 3:
                            panel = this.flowLayoutPanel3;
                            break;
                        case 4:
                            panel = this.flowLayoutPanel4;
                            break;
                        case 5:
                            panel = this.flowLayoutPanel5;
                            break;
                        case 6:
                            panel = this.flowLayoutPanel6;
                            break;
                        case 7:
                            panel = this.flowLayoutPanel7;
                            break;
                        case 8:
                            panel = this.flowLayoutPanel8;
                            break;
                        default:
                            break;
                    }

                    //初始化产品
                    panel.Controls.Clear();
                    group.twoTest = new FormTwo(group.LocalIp, group.LocalPort, _modemAddress, _modemUser, _modemPwd, i, _listType, _stationIp);
                    group.twoTest.OnWrite += TwoTest_OnTesting;
                    //group.threeTest.OnVoiceResult += VoiceTest_OnVoiceResult;
                    group.twoTest.OnFinished += TwoTest_OnFinished;
                    group.twoTest.Show();

                    panel.Controls.Add(group.twoTest);
                    _dictTestTwo.Add(i, group);
                }
            }
            else if (type == "5")
            {
                //修改软件名称
                this.Text = string.Format("友创达信息写入软件自动扫码版本 V{0}", version);

                //默认GPON的SN号码
                string defaultSn = AppSetting.GetValue("DefaultSn");
                if (string.IsNullOrEmpty(defaultSn) == false) _defaultSn = defaultSn;

                //是否写BOB信息
                string writeBob = AppSetting.GetValue("WriteBob");

                _dictWriteScan = new Dictionary<int, WriteGroupScan>();
                for (int i = 1; i <= 8; i++)
                {
                    WriteGroupScan group = new WriteGroupScan();

                    string localIp = AppSetting.GetValue("LocalIp" + i);
                    if (string.IsNullOrEmpty(localIp) == false) group.LocalIp = localIp;
                    string localPort = AppSetting.GetValue("LocalPort" + i);
                    int port;
                    if (string.IsNullOrEmpty(localPort) == false && int.TryParse(localPort, out port)) group.LocalPort = port;

                    FlowLayoutPanel panel = null;

                    //获取需要调用的panel
                    switch (i)
                    {
                        case 1:
                            panel = this.flowLayoutPanel1;
                            break;
                        case 2:
                            panel = this.flowLayoutPanel2;
                            break;
                        case 3:
                            panel = this.flowLayoutPanel3;
                            break;
                        case 4:
                            panel = this.flowLayoutPanel4;
                            break;
                        case 5:
                            panel = this.flowLayoutPanel5;
                            break;
                        case 6:
                            panel = this.flowLayoutPanel6;
                            break;
                        case 7:
                            panel = this.flowLayoutPanel7;
                            break;
                        case 8:
                            panel = this.flowLayoutPanel8;
                            break;
                        default:
                            break;
                    }

                    //初始化产品
                    panel.Controls.Clear();
                    group.RealWrite = new FormRealWriteScan(group.LocalIp, group.LocalPort, _modemAddress, _modemUser, _modemPwd, i, _listType, _defaultSn, _stationIp, writeBob);
                    group.RealWrite.OnWrite += new Action<int>(OnWriteScan_Action);
                    group.RealWrite.OnEndAndWrite += new Action<string, int>(OnEndAndWriteScan);
                    group.RealWrite.Show();
                    panel.Controls.Add(group.RealWrite);

                    _dictWriteScan.Add(i, group);
                }
            }

            else
            {
                MessageBox.Show("软件配置错误，即将关闭");
                Close();
            }


            //等比例缩放
            X = this.Width;
            Y = this.Height;

            setTag(this);

            this.Resize += new EventHandler(Form_Resize);
        }

        private void OnEndAndWriteScan(string bosa, int formNum)
        {
            if (string.IsNullOrEmpty(bosa)) return;

            //终止线程，绑定新的BOSA
            if (_dictWriteScan.TryGetValue(formNum, out WriteGroupScan group))
            {
                group.RealWrite.EndAndWrite(bosa);
            }
        }

        private void OnWriteScan_Action(int formNum)
        {
            WriteGroupScan group = null;
            switch (formNum)
            {
                case 1:
                    _dictWriteScan.TryGetValue(2, out group);
                    //FocusReal(_real2);
                    break;
                case 2:
                    _dictWriteScan.TryGetValue(3, out group);
                    break;
                case 3:
                    _dictWriteScan.TryGetValue(4, out group);
                    break;
                case 4:
                    _dictWriteScan.TryGetValue(5, out group);
                    break;
                case 5:
                    _dictWriteScan.TryGetValue(6, out group);
                    break;
                case 6:
                    _dictWriteScan.TryGetValue(7, out group);
                    break;
                case 7:
                    _dictWriteScan.TryGetValue(8, out group);
                    break;
                case 8:
                    _dictWriteScan.TryGetValue(1, out group);
                    break;
                default:
                    break;
            }

            if (group != null) FocusNext(group.RealWrite);
        }

        /// <summary>
        /// 完成时执行方法
        /// </summary>
        /// <param name="formNum"></param>
        private void TwoTest_OnFinished(int formNum)
        {

            if (_formFree.Count == 0)
            {
                TestTwoGroup group = null;
                _dictTestTwo.TryGetValue(formNum, out group);

                if (group != null) { FocusNext(group.twoTest); }
            }

            lock (_lockObj)
            {
                _formFree.Add(formNum);
            }
        }
        /// <summary>
        /// 测试时执行方法
        /// </summary>
        /// <param name="formNum"></param>
        private void TwoTest_OnTesting(int formNum)
        {
            //根据formNum来确定下一个光标指向哪里
            lock (_lockObj)
            {
                _formFree.Remove(formNum);
            }
            int nextForm = 0;
            if (_formFree.Count == 0) return;
            if (_formFree.Count == 1) nextForm = _formFree[0];
            else
            {
                //找到下一个跳转的地方
                nextForm = (from f in _formFree
                            where f > formNum
                            orderby f
                            select f).FirstOrDefault();

                //如果所有的没有用的FORM都小于此窗口号，则找到最小的窗口号
                if (nextForm <= 0 || nextForm > 8)
                {
                    nextForm = (from f in _formFree
                                orderby f
                                select f).FirstOrDefault();
                }
            }

            TestTwoGroup group = null;
            _dictTestTwo.TryGetValue(nextForm, out group);

            if (group != null) { FocusNext(group.twoTest); }

        }



        private void OnFactory_Action(int formNum)
        {
            ResetGroup group = null;
            switch (formNum)
            {
                case 1:
                    _dictReset.TryGetValue(2, out group);
                    //FocusReal(_real2);
                    break;
                case 2:
                    _dictReset.TryGetValue(3, out group);
                    break;
                case 3:
                    _dictReset.TryGetValue(4, out group);
                    break;
                case 4:
                    _dictReset.TryGetValue(5, out group);
                    break;
                case 5:
                    _dictReset.TryGetValue(6, out group);
                    break;
                case 6:
                    _dictReset.TryGetValue(7, out group);
                    break;
                case 7:
                    _dictReset.TryGetValue(8, out group);
                    break;
                case 8:
                    _dictReset.TryGetValue(1, out group);
                    break;
                default:
                    break;
            }

            if (group != null) FocusNext(group.resetModem);
        }

        private void OnEndAndWrite(string bosa,int formNum)
        {
            if (string.IsNullOrEmpty(bosa)) return;

            WriteGroup group = null;
            //终止线程，绑定新的BOSA
            if(_dictWrite.TryGetValue(formNum,out group))
            {
                group.RealWrite.EndAndWrite(bosa);
            }
        }

        //焦点移动到下一个输入口，写信息的窗口
        private void OnWrite_Action(int formNum)
        {
            WriteGroup group = null;
            switch (formNum)
            {
                case 1:
                    _dictWrite.TryGetValue(2, out group);
                    //FocusReal(_real2);
                    break;
                case 2:
                    _dictWrite.TryGetValue(3, out group);
                    break;
                case 3:
                    _dictWrite.TryGetValue(4, out group);
                    break;
                case 4:
                    _dictWrite.TryGetValue(5, out group);
                    break;
                case 5:
                    _dictWrite.TryGetValue(6, out group);
                    break;
                case 6:
                    _dictWrite.TryGetValue(7, out group);
                    break;
                case 7:
                    _dictWrite.TryGetValue(8, out group);
                    break;
                case 8:
                    _dictWrite.TryGetValue(1, out group);
                    break;
                default:
                    break;
            }

            if (group != null) FocusNext(group.RealWrite);
        }
        //焦点移动到下一个输入口，检查信息的窗口
        private void OnCheck_Action(int formNum)
        {
            MsgCheckGroup group = null;
            switch (formNum)
            {
                case 1:
                    _dictCheck.TryGetValue(2, out group);
                    //FocusReal(_real2);
                    break;
                case 2:
                    _dictCheck.TryGetValue(3, out group);
                    break;
                case 3:
                    _dictCheck.TryGetValue(4, out group);
                    break;
                case 4:
                    _dictCheck.TryGetValue(5, out group);
                    break;
                case 5:
                    _dictCheck.TryGetValue(6, out group);
                    break;
                case 6:
                    _dictCheck.TryGetValue(7, out group);
                    break;
                case 7:
                    _dictCheck.TryGetValue(8, out group);
                    break;
                case 8:
                    _dictCheck.TryGetValue(1, out group);
                    break;
                default:
                    break;
            }

            if (group != null) FocusNext(group.msgCheck);
        }

        private void FocusNext(UserControl userForm)
        {
            if (userForm.InvokeRequired)
            {
                Action<UserControl> d = new Action<UserControl>(FocusNext);
                Invoke(d, userForm);
            }
            else
            {
                userForm.Focus();
                //real.SetFocusMac();
            }
        }

        private void FormModemWrite_FormClosing(object sender, FormClosingEventArgs e)
        {
            //关闭多线程

            if (_dictReset != null && _dictReset.Count > 0)
            {
                ResetGroup resetG = null;
                for(int i = 1; i < _dictReset.Count; i++)
                {
                    if(_dictReset.TryGetValue(i, out resetG))
                    {
                        resetG.resetModem.Stop();
                    }
                }
            }

            if (_dictVoice != null && _dictVoice.Count > 0)
            {
                VoiceTestGroup voiceG = null;
                for(int i = 0; i < _dictVoice.Count; i++)
                {
                    if(_dictVoice.TryGetValue(i,out voiceG))
                    {
                        voiceG.voiceTest.Stop();
                    }
                }
            }
            if (_softType == "3")
                VoiceBaseClass.ExitVoiceCard();

            //关闭ARP线程
            //_clearArp?.Dispose();

            ProcessClass.KillProcess();
            //Application.Exit();           
        }


        #region 自动缩放

        private float X = 0.0f;
        private float Y = 0.0f;

        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ":" + con.Height + ":" + con.Top + ":" + con.Left + ":" + con.Font.Size;
                if (con.Controls.Count > 0)
                {
                    setTag(con);
                }
            }
        }
        private void setControls(float newx, float newy, Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                String[] mytags = con.Tag.ToString().Split(new char[] { ':' });
                float a = Convert.ToSingle(mytags[0]) * newx;
                con.Width = (int)a;
                a = Convert.ToSingle(mytags[1]) * newy;
                con.Height = (int)a;
                a = Convert.ToSingle(mytags[2]) * newy;
                con.Top = (int)a;
                a = Convert.ToSingle(mytags[3]) * newx;
                con.Left = (int)a;
                Single currectsize = Convert.ToSingle(mytags[4]) * newy;
                con.Font = new Font(con.Font.Name, currectsize, con.Font.Style, con.Font.Unit);
                if (con.Controls.Count > 0)
                {
                    setControls(newx, newy, con);
                }
            }
        }

        private void Form_Resize(object sender, EventArgs e)
        {
            float newX = this.Width / X;
            float newY = this.Height / Y;

            setControls(newX, newY, this);
            //this.Text = this.Width.ToString() + "*" + this.Height.ToString();
        }

        #endregion

    }
}
